home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NetWarmer / source / WindowAids.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-11  |  4.6 KB  |  217 lines  |  [TEXT/KAHL]

  1. /* © 1988, Bowers Development Corp. */
  2. /* WindowAids.c */
  3.  
  4. #include "WindowAids.h"
  5.  
  6.  
  7. /*----------*/
  8. ListHandle NewV1List    (bounds, parentWindow)
  9. Rect            bounds;
  10. WindowPtr        parentWindow;
  11. {
  12.     Rect            listBounds;
  13.     Rect            dataBounds;
  14.     Point            cSize;
  15.     ListHandle        list;
  16.  
  17.     listBounds = bounds;
  18.     listBounds.right = listBounds.right - 15;    /*for scroll bar*/
  19.     SetRect (&dataBounds, 0, 0, 1, 0);    /*one column, no rows*/
  20.     SetPt (&cSize, listBounds.right - listBounds.left, 0);
  21.     list = LNew    (&listBounds,    /*dialog item's box*/
  22.                  &dataBounds,    /*one column, no rows*/
  23.                  cSize,            /*cell size: full width, standard height*/
  24.                  0,                /*procid - standard text list*/
  25.                  parentWindow,    /*parent window*/
  26.                  true,            /*draw it*/
  27.                  false,            /*has no grow*/
  28.                  false,            /*no horizontal scroll*/
  29.                  true);            /*vertical scroll*/
  30.     (**list).selFlags = lOnlyOne + lNoNilHilite;
  31.     return (list);
  32. } /*NewV1List*/
  33.  
  34. /*----------*/
  35. void TextIDBox        (textID, bounds)
  36. short        textID;
  37. Rect        bounds;
  38. {
  39.     Handle            text;
  40.  
  41.     text = GetResource ('TEXT', textID);
  42.     if (text != nil) {
  43.         LoadResource (text);
  44.         HLock (text);
  45.         TextBox (&(**text), GetHandleSize (text), &bounds, teJustLeft);
  46.         HUnlock (text);
  47.     }
  48. } /*TextIDBox*/
  49.  
  50. /*----------*/
  51. void PlotIconID        (iconID, bounds)
  52. short        iconID;
  53. Rect        bounds;
  54. {
  55.     Handle            icon;
  56.  
  57.     icon = GetIcon (iconID);
  58.     if (icon != nil) {
  59.         LoadResource (icon);
  60.         PlotIcon (&bounds, icon);
  61.     }
  62. } /*PlotIconID*/
  63.  
  64. /*----------*/
  65. void DrawPictureID    (pictID, bounds)
  66. short        pictID;
  67. Rect        bounds;
  68. {
  69.     PicHandle        pict;
  70.  
  71.     pict = GetPicture (pictID);
  72.     if (pict != nil) {
  73.         LoadResource ((Handle) (pict));
  74.         DrawPicture (pict, &bounds);
  75.     }
  76. } /*DrawPictureID*/
  77.  
  78. /*----------*/
  79. void DrawGrayLine    (bounds)
  80. Rect        bounds;
  81. {
  82.     PenState        savePen;
  83.  
  84.     GetPenState (&savePen);
  85.     PenNormal ();
  86.     PenPat (gray);
  87.     MoveTo (bounds.left, bounds.top);
  88.     LineTo (bounds.right - 1, bounds.bottom - 1);
  89.     SetPenState (&savePen);
  90. } /*DrawGrayLine*/
  91.  
  92. /*----------*/
  93. void UpdatePopup    (bounds, menuID, choice)
  94. Rect        bounds;
  95. short        menuID;
  96. short        choice;
  97. {
  98.     MenuHandle        menu;
  99.     Str255            menuItem;
  100.  
  101.     menu = (MenuHandle) (GetResource ('MENU', menuID));
  102.     if (menu != nil) {
  103.         GetItem (menu, choice, menuItem);
  104.         bounds.left = bounds.left + 12;
  105.         TextBox (&menuItem [1], menuItem [0], &bounds, teJustLeft);
  106.         bounds.left = bounds.left   - 12;
  107.     }
  108.     bounds.right  = bounds.right  - 1;
  109.     bounds.bottom = bounds.bottom - 1;
  110.     FrameRect (&bounds);
  111.     MoveTo (bounds.right, bounds.top + 2);
  112.     LineTo (bounds.right, bounds.bottom);
  113.     LineTo (bounds.left + 2, bounds.bottom);
  114. } /*UpdatePopup*/
  115.  
  116. /*----------*/
  117. void TrackPopup        (bounds, menuID, choice)
  118. Rect        bounds;
  119. short        menuID;
  120. short        *choice;
  121. {
  122.     MenuHandle        menu;
  123.     Point            corner;
  124.     long            result;
  125.  
  126.     menu = (MenuHandle) (GetResource ('MENU', menuID));
  127.     if (menu != nil) {
  128.         InsertMenu (menu, -1);
  129.         corner = topLeft (bounds);
  130.         LocalToGlobal (&corner);
  131.         CheckItem (menu, *choice, true);
  132.         result = PopUpMenuSelect (menu, corner.v, corner.h + 1, *choice);
  133.         CheckItem (menu, *choice, false);
  134.         DeleteMenu (menuID);
  135.         if (HiWord (result) != 0) {
  136.             if (LoWord (result) != *choice) {
  137.                 *choice = LoWord (result);
  138.                 InsetRect (&bounds, 1, 1);
  139.                 InvalRect (&bounds);
  140.             }
  141.         }
  142.     }
  143. } /*TrackPopup*/
  144.  
  145. /*----------*/
  146. Boolean TrackButton    (button, mousePos)
  147. ControlHandle    button;
  148. Point            mousePos;
  149. {
  150.     return (TrackControl (button, mousePos, nil) != 0);
  151. } /*TrackButton*/
  152.  
  153. /*----------*/
  154. void TrackCheck        (checkBox, mousePos, checked)
  155. ControlHandle    checkBox;
  156. Point            mousePos;
  157. Boolean            *checked;
  158. {
  159.     if (TrackControl (checkBox, mousePos, nil) != 0) {
  160.         *checked = !*checked;
  161.         SetCtlValue (checkBox, *checked);
  162.     }
  163. } /*TrackCheck*/
  164.  
  165. /*----------*/
  166. void TrackRadio        (radio, mousePos, choice)
  167. ControlHandle    radio;
  168. Point            mousePos;
  169. short            *choice;
  170. {
  171.     long            refCon;
  172.     short            group;
  173.     ControlHandle    control;
  174.  
  175.     if (TrackControl (radio, mousePos, nil) != 0) {
  176.         refCon = GetCRefCon (radio);
  177.         group = HiWord (refCon);
  178.         *choice = LoWord (refCon);
  179.         control = ((WindowPeek) thePort)->controlList;
  180.         while (control != nil) {
  181.             if ((**control).contrlDefProc == (**radio).contrlDefProc) {
  182.                 refCon = GetCRefCon (control);
  183.                 if (HiWord (refCon) == group) {
  184.                     SetCtlValue (control, 0);
  185.                 }
  186.             }
  187.             control = (**control).nextControl;
  188.         } /*while*/
  189.         SetCtlValue (radio, 1);
  190.     }
  191. } /*TrackRadio*/
  192.  
  193. /*----------*/
  194. void TrackPalette    (palette, mousePos, choice)
  195. ControlHandle    palette;
  196. Point            mousePos;
  197. short            *choice;
  198. {
  199.     if (TrackControl (palette, mousePos, nil) != 0) {
  200.         *choice = GetCtlValue (palette);
  201.     }
  202. } /*TrackPalette*/
  203.  
  204. /*----------*/
  205. void HiliteScroll    (scroll, active)
  206. ControlHandle    scroll;
  207. Boolean            active;
  208. {
  209.     if (scroll != nil) {
  210.         if (active) {
  211.             HiliteControl (scroll, 0);
  212.         } else {
  213.             HiliteControl (scroll, 255);
  214.         }
  215.     }
  216. } /*HiliteScroll*/
  217.